using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
//using Framework.Module.Document.Library.Data;
using Framework.Library;
using Framework.Module;

namespace Framework.Module.Language.Library.DataAccess
{
    public class LanguageInfo
    {
        public string language_culture;
        public string language_name;

        public string Language_Culture
        {
            get {
                return language_culture;
            }
            set {
                this.language_culture = value;
            }
        }
        public string Language_Name
        {
            get {
                return language_name;
            }
            set {
                this.language_name = value;            
            }
        }          
    }
    public class LanguageDataAccess
    {
        public LanguageDataAccess()
        { }

        public Boolean CheckExistValue(string field)
        {
            string strSelect = "select * from Portal_languages where Language_Culture = '"+ field+"'";
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand(strSelect, dbConn);
            dbCmd.CommandType = CommandType.Text;           
                dbConn.Open();
                int i = dbCmd.ExecuteNonQuery();
                if (i > 0)
                    return true;
                else
                    return false;                        
        }

        public DataTable GetAll()
        {
         
            DataTable retVal = null;
            string GetAll_Lang_Str = "select * from Portal_languages";
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand(GetAll_Lang_Str, dbConn);
            dbCmd.CommandType = CommandType.Text;
            try
            {
                retVal = new DataTable();
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                da.Fill(retVal);
            }
            finally
            {
                dbConn.Close();
            }
            return retVal;
        }
      
        public void Insert(LanguageInfo language_info)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Language_Insert", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.Add("@language_culture", language_info.language_culture);
            dbCmd.Parameters.Add("@language_name", language_info.language_name);
          
            try
            {
                if (dbConn.State != ConnectionState.Open)
                {
                    dbConn.Open();
                    dbCmd.ExecuteNonQuery();
                }
            }
            finally
            {
                dbConn.Close();
            }
        }

        public void Update(LanguageInfo language_info)
        {
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            SqlCommand dbCmd = new SqlCommand("Language_Update", dbConn);
            dbCmd.CommandType = CommandType.StoredProcedure;
            dbCmd.Parameters.Add("@language_culture", language_info.language_culture);
            dbCmd.Parameters.Add("@language_name", language_info.language_name);
           
            try
            {
                dbConn.Open();
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }

        public void Delete(string index)
        {
            String strDelete = "Delete Portal_Languages where Language_Culture = '"+ index+"'";
            SqlConnection dbConn = new SqlConnection(AppEnv.ConnectionString);
            dbConn.Open();
            SqlCommand dbCmd = dbConn.CreateCommand();
            dbCmd.CommandType = CommandType.Text;
            dbCmd.CommandText = strDelete;

            try
            {
                dbCmd.ExecuteNonQuery();
            }
            finally
            {
                dbConn.Close();
            }
        }
    }
}
